import { methods, request } from '@/utils/request'; //设置自己的request路径

const actions = {
  getstudentList: {
    //获取学生列表
    name: 'getstudentList',
    url: '/api/freshSystem/teacher/getStuList/',
  },
  getcreateCluster: {
    //按个人创建分群
    name: 'getcreateCluster',
    url: '/api/freshSystem/teacher/addCluster',
  },
  getClusterList: {
    //获取分群列表
    name: 'getClusterList',
    url: '/api/freshSystem/teacher/clusterList/',
  },
  getClusterDetail: {
    //获取分群详情
    name: 'getClusterDetail',
    url: '/api/freshSystem/teacher/clusterDetails/',
  },
  getClusterDelete: {
    //删除分群
    name: 'getClusterDelete',
    url: '/api/freshSystem/teacher/deleteCluster/',
  },
};

const customRequest = (action: any, token: any, formdata: any = null) => {
  const options: any = {
    headers : {
      'Content-Type': 'application/json;charset=utf-8',
      Accept: 'application/json',
      Authorization: localStorage.getItem("token") ? localStorage.getItem("token"):'',
    }
  };
  let url = action.url;
  switch (action.name) {
    case actions.getstudentList.name: //获取学生列表
      options['method'] = methods.get;
      url += formdata;
      // console.log(url);
      break;
    case actions.getcreateCluster.name: //按个人创建分群
      options['method'] = methods.post;
      options['body'] = JSON.stringify(formdata);
      // console.log(url);
      break;
    case actions.getClusterList.name: //获取分群列表
      options['method'] = methods.get;
      url += formdata;
      // console.log(url);
      break;
    case actions.getClusterDetail.name: //获取分群详情
      options['method'] = methods.get;
      url += formdata;
      // console.log(url);
      break;
    case actions.getClusterDelete.name: //删除分群
      options['method'] = methods.delete;
      url += formdata;
      // console.log(url);
      break;
    default:
  }
  return request(url, options);
};

export function getstudentList(token: any, formdata: any) {
  //获取学生列表
  return customRequest(actions.getstudentList, token, formdata);
}
export function getcreateCluster(token: any, formdata: any) {
  //按个人创建分群
  return customRequest(actions.getcreateCluster, token, formdata);
}
export function getClusterList(token: any, formdata: any) {
  //获取分群列表
  return customRequest(actions.getClusterList, token, formdata);
}
export function getClusterDetail(token: any, formdata: any) {
  //获取分群详情
  return customRequest(actions.getClusterDetail, token, formdata);
}
export function getClusterDelete(token: any, formdata: any) {
  //获取分群详情
  return customRequest(actions.getClusterDelete, token, formdata);
}
